package norbert.utils {
	/* IMPORTS */
	
	import flash.events.EventDispatcher;
	import mx.logging.*;
	
	public class EventHandler extends MXMLObject {
		/* PROPERTIES */
		
		private static var logger: ILogger = Log.getLogger("norbert.utils.EventHandler");
		
		protected var eventDispatcher: EventDispatcher;
		
		private var _eventType: String;
		[Bindable]
		public function get eventType(): String {
			return _eventType;
		}
		public function set eventType(value: String): void {
			removeEventDispatcherListener();
			_eventType = value;
			addEventDispatcherListener();
		}
		
		/* METHODS */
		
		/* Szándékosan nem property, hogy az MXML kódból ne legyen látható */
		public function setEventDispatcher(dispatcher: EventDispatcher): void {
			removeEventDispatcherListener();
			eventDispatcher = dispatcher;
			addEventDispatcherListener();
		}
		
		private function addEventDispatcherListener(): void {
			if (eventDispatcher && eventType != null && eventType != "") {
				eventDispatcher.addEventListener(eventType, listener);
			}
		}
		
		private function removeEventDispatcherListener(): void {
			if (eventDispatcher && eventType != null && eventType != "") {
				eventDispatcher.removeEventListener(eventType, listener);
			}
		}
		
		/* A leszármozattaknak ezt kell túlterhelniük */
		protected function listener(event: Event): void { }
	}
}
